<template>
  <div class="app-container">
    <h2>申请退款</h2>
    <el-form :model="refundForm" label-width="100px">
      <el-form-item label="订单编号">
        <el-input v-model="refundForm.orderNumber" placeholder="请输入订单编号" />
      </el-form-item>
      <el-form-item label="退款金额">
        <el-input-number v-model="refundForm.refundAmount" :min="0.01" :step="0.01" placeholder="请输入退款金额" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="requestRefund">申请退款</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { requestRefund } from '@/api/refund'

export default {
  name: 'RefundApply',
  data() {
    return {
      refundForm: {
        orderNumber: '',
        refundAmount: 0.01
      }
    }
  },
  methods: {
    async requestRefund() {
      if (!this.refundForm.orderNumber || this.refundForm.refundAmount <= 0) {
        this.$message.error('请正确填写退款信息！');
        return;
      }
      const response = await requestRefund(this.refundForm)
      this.$message.success(response)
    }
  }
}
</script>
